package vn.com.unit.springmvc.mvc;

 import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import vn.com.unit.springmvc.domain.AssetType;
import vn.com.unit.springmvc.repo.AssetTypeDao;

@Controller
@RequestMapping(value="/")
public class IndexController
{
    //@Autowired
    //private AssetTypeDao assetTypeDao;

    @RequestMapping(method=RequestMethod.GET)
    public String index(Model model)
    {
        //model.addAttribute("newAssetType", new AssetType());
        //model.addAttribute("assetTypes", assetTypeDao.findAllOrderedByName());
        return "index";
    }

//    @RequestMapping(method=RequestMethod.POST)
//    public String registerNewAssetType(@Valid @ModelAttribute("newAssetType") AssetType newAssetType, BindingResult result, Model model)
//    {
//        if (!result.hasErrors()) {
//            assetTypeDao.register(newAssetType);
//            return "redirect:/";
//        }
//        else {
//            model.addAttribute("assetTypes", assetTypeDao.findAllOrderedByName());
//            return "index";
//        }
//    }
    
//    @RequestMapping(method=RequestMethod.POST)
//    public String deleteNewAssetType(@Valid @ModelAttribute("deleteAssetType") String id, Model model)
//    {
//    	assetTypeDao.delete(id);
//    	return "redirect:/";
//    }
    
//    @RequestMapping(value="/delete", method=RequestMethod.GET)
//    public String deleteAssetTypeById(@RequestParam String id)
//    {
//         assetTypeDao.delete(id);
//         //model.addAttribute("assetTypes", assetTypeDao.findAllOrderedByName());
//         //return "index";
//         return "redirect:/";
//    }
    
//    @RequestMapping(value="/delete/{id}", method=RequestMethod.GET)
//    public @ResponseBody String deleteAssetTypeById(@PathVariable("id") String id)
//    {
//         assetTypeDao.delete(id);
//         //model.addAttribute("assetTypes", assetTypeDao.findAllOrderedByName());
//         //return "index";
//         return "index";
//    }
}
